{eval
	$_HEAD[title] = "会员注册";
}
{include mobile_template('header')}
<div class="panel-comm">
	<div class="panel-body">
		<div class="form-box">
			<form action="{url member/mobile/do/reg}" method="POST">

				<input type="hidden" name="forward" value="$forward" />
				<input type="hidden" name="uniq" value="$user->session_id" />
				<!--{if $passport}-->
				<input type="hidden" name="passport" value="$passport_type">
				<input type="hidden" name="passport_id" value="$passport_id">
				<!--{/if}-->

				<!--{if $_G['passport_apis']}-->
				<div class="form-item">
					<fieldset>
						<legend>使用合作网站帐号登录：</legend>
						<!--{if $passport && $title}-->
							<p>$title</p>
						<!--{else}-->
							<!--{loop $_G['passport_apis'] $passport_name $passport_title}-->
								<a href="{url member/passport/op/login/type/$passport_name/source/mobile_web}">
									<img src="{URLROOT}/static/images/passport/{$passport_name}_n.png">
									$passport_title
								</a>
							<!--{/loop}-->
						<!--{/if}-->
					</fieldset>
				</div>
				<!--{/if}-->
				<div class="form-item">
					<label>用户名：
						<input name="username" id="username" placeholder="请输入用户名" value="$username" type="text" required>
					</label>
				</div>
				<div class="form-item">
					<label>E-mail：
						<input name="email" id="email" placeholder="请输入电子邮箱" value="$email" type="email" required>
					</label>
				</div>
				<!--{if !$passport || ($passport && S('member:passport_pw'))}-->
				<div class="form-item">
					<label>登录密码：
					<input name="password" id="password" placeholder="请输入登录密码" value="" type="password" required>
					</label>
				</div>
				<div class="form-item">
					<label>确认密码：
					<input name="password2" id="password2" placeholder="请重新输入密码" value="" type="password" required>
					</label>
				</div>
				<!--{/if}-->
				<!--{if S('member:mobile_verify')}-->
				<div class="form-item">
					<label>手机号验证：</label>
					<input style="width:200px;" name="mobile" id="mobile" placeholder="请输入手机号" value="" type="text" required>
					<span class="abtn" id="btn_mobile"><a href="javascript:;" onclick="check_mobile();">发送验证码</a></span> 
					<span id="msg_mobile"></span>
				</div>
				<div class="form-item">
					<label>手机号验证码：</label>
					<input style="width:200px;" onblur="check_mobile_verify()" name="mobile_verify" id="mobile_verify" placeholder="请输入手机号验证码" value="" type="text" required>
					<span id="msg_mobile_verify"></span>
				</div>
				<!--{/if}-->
				<!--{if $MOD['seccode_reg']}-->
				<div class="form-item">
					<label>验证码：
						<div>
							<!--{if S('seccode_type')=='geetest' }-->
                            	<!--{print ms_geetest::float()}-->
                            	<!--{else}-->
							<input style="width:200px;" name="seccode" id="seccode" placeholder="请输入验证码" value="" type="text" required>
							<span data-name="seecode"></span>
							<!--{/if}-->
						</div>
					</label>
				</div>
				<!--{/if}-->
				<div class="form-item">
					<div class="btn-group-vertical btn-group-mt10 full-width">
						<button type="submit" value="Yes" name="dosubmit" class="btn btn-mycolor">提交注册</button>
						<!--{if $passport}-->
							<a class="btn btn-default" href="{url member/passport/op/bind/type/$passport_type/source/mobile_web}"><span>绑定已存在账号</span></a>
							<!--{if S('member:passport_reg_skip')}-->
								<a class="btn btn-default" href="{url member/passport/op/auto_reg/type/$passport_type/source/mobile_web}"><span>跳过本地注册</span></a>
							<!--{/if}-->
						<!--{else}-->
							<a href="{url member/mobile/do/login}" class="btn btn-default">已有帐号，登录</a>
						<!--{/if}-->
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
function check_mobile(obj) {
	var mobile = $('#mobile').val().trim();
	if(!mobile) {
		alert('请输入手机号码');
		return;
	}
	$.post(Url('member/ajax/op/check_mobile'), {mobile:mobile,in_ajax:1}, function(data) {
		if(data=='OK') {
			$('#msg_mobile').hide();
			$('#btn_mobile').hide();
			member_mobile_send(mobile);
		} else if(data=='SUCCEED') {
			$('#msg_mobile').html('手机号验证成功。').show();
			$('#btn_mobile').hide();
		} else {
			$('#msg_mobile').html(data).show();
			$('#btn_mobile').show();
		}
	});
}

var mobile_verify_time = 59;
var mobile_verify_time_handle = null;
function member_mobile_send(mobile) {
	if(mobile_verify_time_handle) clearInterval(mobile_verify_time_handle);
	$('#msg_mobile').html('正在发送手机验证码...').show();
	$.post(Url('member/ajax/op/send_verify'), {'mobile':mobile,'in_ajax':1}, function(data) {
		data = data.trim();
		$('#msg_mobile').html('').hide();
		if(data=='OK'||is_numeric(data)) {
			if(data=='OK') {
			$('#msg_mobile').html('验证码已发送，请在下方文本框内输入验证码。').show();
			} else if(is_numeric(data)) {
				mobile_verify_time = data;
			}
			mobile_verify_time_handle = window.setInterval(function() {
				if(mobile_verify_time <= 0) {
					$('#msg_mobile').html('');
					$('#btn_mobile').show();
					mobile_verify_time = 59;
					clearInterval(mobile_verify_time_handle);
				} else {
					$('#msg_mobile').html('重新发送验证码('+mobile_verify_time--+')').show();
				}
			}, 1000);
		} else if(is_message(data)) {
			myAlert(data);
		} else {
			alert('手机短信发送失败。');
		}
	});
}

function check_mobile_verify() {
	var serial = $('#mobile_verify').val().trim();
	if(serial=='') {
		$('#msg_mobile_verify').html('<span style="color:red">请输入验证码</span>').show();
		return;
	}
	$.post(Url('member/ajax/op/check_mobile_verify'), {'serial':serial,'in_ajax':1}, function(data) {
		if(data=='OK') {
			if(mobile_verify_time_handle) clearInterval(mobile_verify_time_handle);
			$('#msg_mobile_verify').html('<span style="color:green">短信验证成功！</span>').show();
		} else {
			$('#msg_mobile').html('<span style="color:red">短信验证失败！</span>').show();
		}
	});
}

$(document).ready(function() {
	$('span[data-name="seecode"]').m_seccode();
	check_mobile_verify();
});
</script>
{include mobile_template('footer')}